package com.shengwei.truck.driver.vm;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.shengwei.truck.driver.bean.JsonPostFileData;
import com.shengwei.truck.driver.bean.Result;
import com.shengwei.truck.driver.model.DataSource;
import com.shengwei.truck.driver.model.Repository;
import java.io.File;

/**
 * 个人信息ViewModel层
 */
public class PersonalInfoViewModel extends ViewModel {
    private Repository mRepository; //M层引用
    MutableLiveData<Result<String>> updtUserLiveData = new MutableLiveData<>();
    MutableLiveData<Result<JsonPostFileData>> postFileLiveData = new MutableLiveData<>();
    private MutableLiveData<Result<String>> smsLiveData = new MutableLiveData<>();

    public MutableLiveData<Result<JsonPostFileData>> getPostFileLiveData() {
        return postFileLiveData;
    }

    public MutableLiveData<Result<String>> getUpdtUserLiveData() {
        return updtUserLiveData;
    }
    public PersonalInfoViewModel(Repository repository) {
        mRepository = repository;
    }
    public PersonalInfoViewModel() {
        mRepository = Repository.getInstance(DataSource.getSingleInstance());
    }

    public MutableLiveData<Result<String>> getSmsLiveData() {
        return smsLiveData;
    }

    /**获取短信验证码
     * VM层调用M层（Repository+DataSource）
     * @param pageType : USER_REGISTER(注册页面),FORGET_PASSWORD（忘记密码页面）,CHANGE_PASSWORD（修改密码页面）
     * @return
     */
    public MutableLiveData<Result<String>> getSmsCode(String mobileNum,String pageType) {
        smsLiveData = mRepository.getSmsCode(mobileNum,pageType,smsLiveData);
        return smsLiveData;
    }

    /**
     * step1.调用文件服务器的上传文件接口，上传图片文件到服务器，服务器生成并返回图片URL地址
     * @param file：文件
     * @return
     */
    public void postImagFile(File file,boolean isThumb) {
        mRepository.postPicture(file,isThumb,postFileLiveData);
    }


    /**
     * step2.调用业务服务器的上传头像接口，上传图片URL与本次业务的标识如“头像”，最终完成修改头像操作
     * @param avatarThumbUrl:缩略图地址
     * @param avatarUrl： 原图地址
     */
   public void updateUserInfo(String idCard,String name,String avatarThumbUrl,String avatarUrl,String smsCode) {
       mRepository.updateUserInfo(idCard,name,avatarThumbUrl,avatarUrl,smsCode,updtUserLiveData);
   }

}